package edu.stthomas.seis752.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import edu.stthomas.seis752.model.Media;

@Repository
public class MediaDaoImpl implements MediaDao {

	@PersistenceContext
	private EntityManager manager;

	@Override
	public List<Media> getUserMedia(long userId) {
	    List<Media> mediaList = null;
	    // get the list in descending order based on the data uploaded
        Query  query = manager.createQuery("FROM Media where owner_id =:userId order by create_date desc");
        query.setParameter("userId", userId);
        mediaList = (List<Media>) query.getResultList();
        return mediaList;
	}

	@Override
	public void addMedia(Media media) {
		manager.persist(media);
	}

}
